<?php

function form_konfigurasi_setup_validasi(){
	$errsubmit = false;
	$err = array();
	  
	
	$query = "SELECT * FROM pr_konfigurasi_pajak ORDER BY kolom_id ASC";	
	$result = my_query($query);

 
	while( $row = my_fetch_array($result) ){
		if($row['form_type'] =='persen'){
			if(! is_numeric($_POST['fi_'.$row['kolom_id']])){
				$errsubmit = true;
				$err[] = $row['kolom_label']." belum benar";
			}elseif( (int) $_POST['fi_'.$row['kolom_id']] > 100 ){
				$errsubmit = true;
				$err[] = $row['kolom_label']." belum benar";
			}
		}
		elseif($row['form_type'] =='money'){
			if(! is_numeric( set_text_as_number( $_POST['fi_'.$row['kolom_id']]))){
				$errsubmit = true;
				$err[] = $row['kolom_label']." belum benar";
			}
		}
	}
	if( $errsubmit){
		return $err;
	}
	
	return $errsubmit;
}

function form_konfigurasi_setup(){
	my_set_file_js(
		array(
			'components/system/jquery/jquery.formatCurrency-1.4.0.js', 
			'components/system/jquery/combomulti/jquery.chainedSelects.js',
			'components/system/js/calendar/calendarDateInput.js' 
		)
	);
	$query = "SELECT * FROM pr_konfigurasi_pajak ORDER BY kolom_id ASC";	
	$result = my_query($query);

	$view = form_header( "..." , "..."  );
	while( $row = my_fetch_array($result) ){
		if($row['form_type'] =='persen')$size = 5;
		elseif($row['form_type'] =='kode')$size = 10;
		elseif($row['form_type'] =='money')$size = 15;
		else $size= 45;
		if($row['form_type'] =='money'){
			$val=rp_format($row['value']);
		}else{
			$val=$row['value'];
		}
			
		$fields = array(
			'name'=>'fi_'.$row['kolom_id'],
			'value'=>isset($_POST['fi_'.$row['kolom_id']]) ? $_POST['fi_'.$row['kolom_id']]: $val,
			'size'=>$size
	);
	if($row['form_type'] =='textarea')
		$form = form_textarea($fields).trim($row['satuan']);
	elseif($row['form_type'] =='money')
		$form = form_money($fields).' ' .trim($row['satuan']);
	else
		$form = form_dynamic($fields).($row['form_type'] =='persen' ?'%':'').trim($row['satuan']);
	$view .= form_field_display( $form   , $row['kolom_label']   ) ;
	
	}
 	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 

	$view .= form_field_display( $form_submit .' '.$form_back  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
}

function submit_konfigurasi_setup(){
		$query = "SELECT * FROM pr_konfigurasi_pajak 
		ORDER BY kolom_id ASC";
		$result = my_query($query);
		$datas = array(); 
		while($te = my_fetch_array($result) ){ 
			if($te['form_type'] =='money'){
				$val = set_text_as_number($_POST['fi_'.$te['kolom_id']]) ;
			}else{
				$val = $_POST['fi_'.$te['kolom_id']] ;
			}
		
			$datas['value']=my_type_data_str($val ); 
			my_update_record( 'pr_konfigurasi_pajak', 'kolom_id',$te['kolom_id'],$datas);
		}
		return true;
	}
function konfigurasi_value($konfigurasi_id,$kolom_id){
	$query = "SELECT value FROM pr_konfigurasi_detail 
		WHERE konfigurasi_id='{$konfigurasi_id}' AND kolom_id='{$kolom_id}'
		ORDER  BY konfigurasi_detail_id DESC LIMIT 1";
	$result = my_query($query );
	$row = my_fetch_array($result);
	return $row['value'];
}
